package nk.mygraph;

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

/**
 * 对stage进行监听事件*/



public class Test4 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        final Stage stage = primaryStage;

        Scene scene = new Scene(new Group());
        Scene scene1 = new Scene(new Group());
        scene.setFill(Color.rgb(233,23,23));
        scene1.setFill(Color.rgb(12,12,12));
        //stage.setFullScreen(true);
        primaryStage.setOnShown(new EventHandler<WindowEvent>() {
            public void handle(WindowEvent event) {

            }
        });
        primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
            public void handle(KeyEvent event) {
                System.out.println("Key pressed: " + event.toString());
                KeyCode code = event.getCode();
                switch(code.impl_getCode()) {
                    case 'G' : { // 27 = ESC key
                        stage.close();
                        break;
                    }
                    case 'A' : { // 10 = Return
                        stage.setWidth( stage.getWidth() * 2);
                    }
                    default:  {
                        System.out.println("Unrecognized key");
                    }
                }
            }
        });

        BorderPane pane = new BorderPane();
        scene.setRoot(pane);

        //设置面板鼠标的图标
        scene.setCursor(Cursor.CLOSED_HAND);
        stage.setScene(scene);

        stage.show();
    }
}
